package com.fr.web.core.service;

import com.fr.base.BaseUtils;
import com.fr.base.core.html.Tag;
import com.fr.base.core.json.JSONArray;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.core.util.TemplateUtils;
import com.fr.base.core.util.vt.VT4FR;
import com.fr.base.core.util.vt.VT4FR.FUNC;
import com.fr.report.ParameterReport;
import com.fr.report.ReportParameterAttr;
import com.fr.report.TemplateWorkBook;
import com.fr.report.core.ReportUtils;
import com.fr.report.parameter.ParameterUI;
import com.fr.web.Repository;
import com.fr.web.core.HTMLWriter;
import com.fr.web.core.HTMLWriterUtils;
import com.fr.web.core.SessionIDInfor;
import com.fr.web.core.chwriter.FormCellWriter;
import java.io.PrintWriter;
import java.util.Map;

public abstract class RTypeService
{
  public static void dealWithLoading(Repository paramRepository, PrintWriter paramPrintWriter, String paramString, boolean paramBoolean)
    throws Exception
  {
    Map localMap = paramRepository.checkoutTplContext();
    localMap.put("sessionID", paramRepository.getSessionIDInfor().getSessionID());
    localMap.put("rtype", paramString);
    int i = -1;
    if ((!("page".equals(paramString))) && (!("preview".equals(paramString))))
      i = paramRepository.getSessionIDInfor().getReportCount();
    JSONArray localJSONArray = new JSONArray();
    for (int j = 0; j < i; ++j)
      localJSONArray.put(new JSONObject().put("title", paramRepository.getSessionIDInfor().getReportName(j)));
    localMap.put("sheets", localJSONArray);
    localMap.put("param", config4ParameterPanel(paramRepository, paramBoolean));
    localMap.put("browserbg", HTMLWriterUtils.jsonBackground(ReportUtils.getBrowserBackgroundFromWorkBook(paramRepository.getSessionIDInfor().getContextBook()), paramRepository));
    String str = BaseUtils.readResourceAsString("/com/fr/web/core/js/" + paramString + ".js");
    localMap.put("rtype_js", str);
    TemplateUtils.dealWithTemplate("/com/fr/web/core/tpl/loading.tpl", paramPrintWriter, localMap);
    paramPrintWriter.flush();
    paramPrintWriter.close();
  }

  public static JSONObject config4ParameterPanel(Repository paramRepository, boolean paramBoolean)
    throws JSONException
  {
    SessionIDInfor localSessionIDInfor = paramRepository.getSessionIDInfor();
    JSONObject localJSONObject = new JSONObject();
    ReportParameterAttr localReportParameterAttr = (localSessionIDInfor.getWorkBookDefine() == null) ? null : localSessionIDInfor.getWorkBookDefine().getReportParameterAttr();
    if ((!(paramBoolean)) || (localReportParameterAttr == null))
      return localJSONObject;
    ParameterUI localParameterUI = localReportParameterAttr.getParameterUI();
    if ((!(VT4FR.PARAMETER_INTERFACE.support())) || (!(localReportParameterAttr.isShowWindow())) || (localParameterUI == null))
      return localJSONObject;
    ParameterReport localParameterReport = localParameterUI.getParameterForm();
    if (localParameterReport != null)
    {
      Tag localTag = HTMLWriter.getInstance().writeJSReport(localParameterReport, 0, new FormCellWriter(paramRepository, 0, "parameter"), paramRepository);
      localSessionIDInfor.setAttribute("paramsheet", localParameterReport);
      localJSONObject.put("html", localTag.toHtml());
      localJSONObject.put("showType", localReportParameterAttr.getWindowPosition());
      localJSONObject.put("alignLocation", localReportParameterAttr.getAlign());
      if (localReportParameterAttr.getWindowPosition() == 0)
        localJSONObject.put("paramWindowTitle", localReportParameterAttr.getParameterWindowTitle());
      int i = 0;
      int j = 0;
      int k = localParameterReport.getColumnCount();
      while (j < k)
      {
        i += localParameterReport.getColumnWidth(j);
        ++j;
      }
      localJSONObject.put("paramWidth", i);
      localJSONObject.put("delay", localReportParameterAttr.isDelayPlaying());
      localJSONObject.put("parambg", HTMLWriterUtils.jsonBackground(localReportParameterAttr.getBackground(), paramRepository));
    }
    return localJSONObject;
  }
}